//
//  AppDelegate.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/5/14.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "AppDelegate.h"
#import "WMPageController.h"
#import "HotCommentVC.h"
#import "EnterLayoutVC.h"
#import "FindTravellingVC.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    // deault
    [[DataBaseHandle shareDataBaseHandle] openDB];
    [[DataBaseHandle shareDataBaseHandle] creatTableWithSQname:@"users"];
    [[DataBaseHandle shareDataBaseHandle] creatDicountTableWithSQname:@"discount"];
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    self.window.rootViewController = tabBar;
    
    //make tabBar
    RecommendViewController *recommendVC = [[RecommendViewController alloc] init];
    UINavigationController *recommendNC = [[UINavigationController alloc] initWithRootViewController:recommendVC];
    recommendNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"tuijian"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ] tag:1001];
    recommendNC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tuijian_2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    recommendNC.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -40);
    
    
    DestinationViewController *destinationVC = [[DestinationViewController alloc] init];
    UINavigationController *destinationNC = [[UINavigationController alloc] initWithRootViewController:destinationVC];
    destinationNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"mudidi"] tag:1002];
    destinationNC.tabBarItem.selectedImage = [[UIImage imageNamed:@"mudidi2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    WMPageController *pageController = [self getPages];
    UINavigationController *CommunityNC = [[UINavigationController alloc] initWithRootViewController:pageController];
    CommunityNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"shequ"] tag:1003];
    CommunityNC.tabBarItem.selectedImage = [[UIImage imageNamed:@"shequ2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    MineViewController *mineVC = [[MineViewController alloc] init];
    UINavigationController *mineNC = [[UINavigationController alloc] initWithRootViewController:mineVC];
    mineNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"user"] tag:1004];
    mineNC.tabBarItem.selectedImage = [[UIImage imageNamed:@"user2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    tabBar.viewControllers = @[recommendNC, destinationNC, CommunityNC, mineNC];
    
    //导航器颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:53 / 255.0 green:176 /255.0 blue:131 / 255.0 alpha:1.0]];
    
    //直接将UMSocial_Sdk_4.2.1 导入工程就可以了
    //然后按照友盟文档就可以了
    [UMSocialData setAppKey:@"558936d367e58eb81b001298"];

 
    // Override point for customization after application launch.
    return YES;
}

- (WMPageController *) getPages {
    //WMPageController中包含的页面数组
    NSArray *controllers = [NSArray arrayWithObjects:[HotCommentVC class], [EnterLayoutVC class], [FindTravellingVC class],nil];
    //WMPageController控件的标题数组
    NSArray *titles = [NSArray arrayWithObjects:@"热议", @"进入版面",@"找旅伴", nil];
    //用上面两个数组初始化WMPageController对象
    WMPageController *pageController = [[WMPageController alloc] initWithViewControllerClasses:controllers andTheirTitles:titles];
    //设置WMPageController每个标题的宽度
    pageController.menuItemWidth = 100;
    //设置WMPageController标题栏的高度
    pageController.menuHeight = 60;
    pageController.selectIndex = 0;
     pageController.menuViewStyle = WMMenuViewStyleLine;
    pageController.menuBGColor = [UIColor colorWithRed:53 / 255.0 green:176 /255.0 blue:131 / 255.0 alpha:1.0];
    //设置WMPageController选中的标题的颜色
    pageController.titleColorSelected = [UIColor whiteColor];
    pageController.progressColor = [UIColor clearColor];
    return pageController;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
